//
//  NoticeCell.m
//  sensen_ios
//
//  Created by 小贝 on 16/3/24.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "NoticeCell.h"
@interface NoticeCell()
{
    UILabel *contentLabel;//内容
    UIImageView *imgView;//图片
}
@end
@implementation NoticeCell

+ (NoticeCell *)getNoticeCellWith:(UITableView *)tableView indentifer:(NSString *)indentifer{
    NoticeCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifer];
    if (cell == nil) {
       cell = [[NoticeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifer];
    }
    return cell;
}
//noticemodel的set方法
- (void)setNoticeModel:(NoticeModel *)noticeModel{
    _noticeModel = noticeModel;
    [self _createView];
    [self _setFrame];
}
//视图初始化
- (void)_createView{
    for (UIView *view in self.contentView.subviews) {
    
        [view removeFromSuperview];
    }
    contentLabel = [[UILabel alloc] init];
    contentLabel.textColor = [UIColor darkGrayColor];
    contentLabel.font = [UIFont systemFontOfSize:13];
    
    imgView = [[UIImageView alloc] init];
    [self.contentView addSubview:contentLabel];
    [self.contentView addSubview:imgView];
}
//设置视图大小
- (void)_setFrame{
    contentLabel.text = _noticeModel.post_title;
    contentLabel.numberOfLines = 3;//行数
    CGFloat margin_x = 15;//左间距
    CGFloat margin_y = 10;//上间距
    CGFloat contentLabel_width;//公告内容宽度
    CGFloat contentLabel_y;
    if ([_noticeModel.main_img isStringNull]) {
        contentLabel_width = self.bounds.size.width - 2*margin_x;
        contentLabel_y = margin_y;
    }else{
        contentLabel_width = self.bounds.size.width - 3*margin_y - 52;
        contentLabel_y = margin_x;
    }
    CGSize contentLabel_size = [contentLabel sizeThatFits:CGSizeMake(contentLabel_width, MAXFLOAT)];
    [contentLabel setFrame:CGRectMake(margin_x, contentLabel_y, contentLabel_width, contentLabel_size.height)];
    CGFloat imageView_width = 52;//图片的高度
    //判断有无图片
    if(![_noticeModel.main_img isStringNull]){
        NSURL *url = [NSURL URLWithString:_noticeModel.main_img];
        [imgView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"defaultImage"]];
        [imgView setFrame:CGRectMake(CGRectGetMaxX(contentLabel.frame)+5, 5, imageView_width, imageView_width)];
    }

    [BoyeViewHandle lineCreatedInView:self fram:CGRectMake(0, 62, SCREEN_WIDTH, 1) color:Gray_COLOR];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
